$(document).ready(function ($) {
    var $timeline_block = $('.cd-timeline-block');

//hide timeline blocks which are outside the viewport
    
    $timeline_block.each(function () {
        if ($(this).offset().top > $(window).scrollTop() + $(window).height() * 0.75) {
            $(this).find('.cd-timeline-img, .cd-timeline-content').addClass('is-hidden');
        } else {
            if ($(this).hasClass('readN') && $(this).attr('data-tp-evt') !== 'crd-msg') {
                idUnread = $(this).attr('data-co-evt').replace('evt', '');
                actRead = '/coordenacao/alterarmsg?op=read&id=' + idUnread;
                block = $(this);
                $.ajax(actRead).done(function () {
                    notificaUser();
                    block.removeClass('readN');
                });
            }
        }
    });

//on scolling, show/animate timeline blocks when enter the viewport
    $(window).on('scroll', function () {
        $timeline_block.each(function () {
            if ($(this).offset().top <= $(window).scrollTop() + $(window).height() * 0.75 && $(this).find('.cd-timeline-img').hasClass('is-hidden')) {
                $(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in');
                var tpevt = $(this).attr('data-tp-evt');
                var ignore = ["crd-msg", "apr-msg", "bad-msg"];
                if ($(this).hasClass('readN') && $.inArray(tpevt, ignore) === -1) {
                    console.log(tpevt + ': ' + $.inArray(tpevt, ignore));
                    idUnread = $(this).attr('data-co-evt').replace('evt', '');
                    actRead = '/coordenacao/alterarmsg?op=read&id=' + idUnread;
                    block = $(this);
                    $.ajax(actRead).done(function () {
                        notificaUser();
                        block.removeClass('readN');
                    });
                }
            }
        });
    });
});